import http from '@/utils/request/http'

//#region 角色api 
// 角色分页列表
const rolePage = (params: any) => {
    return http.get('/v1/role/page', params, { successTip: false })
}
// 更新角色菜单
const updatePerm = (params: any) => {
    return http.put('/v1/role/updatePerm', params);
}
// 创建
const createRole = (params: any) => {
    return http.post('/v1/role/create', params)
}
// 编辑
const editRole = (params: any) => {
    return http.put('/v1/role/edit', params);
}
// 删除
const delRole = (id: number | string) => {
    return http.del('/v1/role/del', { id })
}
// 查询所有角色
const selectRole = (successTip) => {
    return http.get('/v1/role/select', null, { successTip })
}
//#endregion

//#region 菜单api 
// 查询菜单树
const menuTree = (successTip: boolean = false) => {
    return http.get('/v1/menu/tree', null, { successTip })
}
// 创建菜单
const createMenu = (params: any) => {
    return http.post('/v1/menu/create', params)
}
// 编辑
const editMenu = (params: any) => {
    return http.put('/v1/menu/edit', params);
}
// 删除
const delMenu = (id: number | string) => {
    return http.del('/v1/menu/del', { id })
}
// 根据角色id获取菜单
const getMenuIdByRole = (roleId: number | string, successTip: boolean = false) => {
    return http.get('/v1/menu/getMenuIdByRole', { roleId }, { successTip })
}
//#endregion

//#region 用户api
// 用户分页列表
const userPage = (params: any) => {
    return http.get('/v1/user/page', params, { successTip: false })
}
// 创建系统用户
const createUser = (params: any) => {
    return http.post('/v1/user/create', params)
}
// 编辑系统用户
const editUser = (params: any) => {
    return http.put('/v1/user/edit', params)
}
// 删除系统用户
const delUser = (id: number | string) => {
    return http.del('/v1/user/del', { id })
}
// 根据用户id获取角色
const getRoleIdByUser = (userId: number | string, successTip: boolean = false) => {
    return http.get('/v1/user/getRoleIdByUser', { userId }, { successTip })
}
// 更新用户角色
const updateUserRole = (params: any) => {
    return http.put('/v1/user/updateRole', params);
}
// 重置密码
const resetPwd = (params: any) => {
    return http.put('/v1/user/resetPwd', params)
}
//#endregion

//#region 公司api
// 公司分页列表
const companyPage = (params: any) => {
    return http.get('/v1/company/page', params, { successTip: false })
}
// 创建公司
const createCompany = (params: any) => {
    return http.post('/v1/company/create', params)
}
// 编辑公司
const editCompany = (params: any) => {
    return http.put('/v1/company/edit', params)
}
// 创建公司用户
const createCompUser = (params: any) => {
    return http.post('/v1/company/createUser', params)
}
//#endregion

//#region 系统字典api
// 角色分页列表
const dictionaryPage = (params: any) => {
    return http.get('/v1/dictionary/page', params, { successTip: false })
}
// 获取所有系统字典
const selectDictionary = (params, successTip) => {
    return http.get('/v1/dictionary/select', params, { successTip })
}
// 获取字典模块
const selectDictionaryEnum = (successTip) => {
    return http.get('/v1/dictionary/enum', null, { successTip })
}
// 创建字典
const crateDictionary = (params) => {
    return http.post('/v1/dictionary/create', params)
}
// 删除系统用户
const delDictionary = (id: number | string) => {
    return http.del('/v1/dictionary/del', { id })
}
//#endregion

export default {
    rolePage,
    updatePerm,
    editRole,
    delRole,
    selectRole,
    createRole,
    menuTree,
    createMenu,
    editMenu,
    delMenu,
    getMenuIdByRole,
    userPage,
    createUser,
    editUser,
    delUser,
    resetPwd,
    updateUserRole,
    getRoleIdByUser,
    companyPage,
    createCompany,
    editCompany,
    createCompUser,
    selectDictionary,
    selectDictionaryEnum,
    crateDictionary,
    dictionaryPage,
    delDictionary
}